/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package cz.vutbr.fit.xzemko01.tfmcbs.model.impl;

import cz.vutbr.fit.xzemko01.tfmcbs.model.Interface;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Requier;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Usage;

import cz.vutbr.fit.xzemko01.tfmcbs.model.meta.TfmcbsPackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Usage</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link cz.vutbr.fit.xzemko01.tfmcbs.model.impl.UsageImpl#getRequier <em>Requier</em>}</li>
 *   <li>{@link cz.vutbr.fit.xzemko01.tfmcbs.model.impl.UsageImpl#getInterface <em>Interface</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class UsageImpl extends RelationshipImpl implements Usage {
	/**
	 * The cached value of the '{@link #getRequier() <em>Requier</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRequier()
	 * @generated
	 * @ordered
	 */
	protected Requier requier;

	/**
	 * The cached value of the '{@link #getInterface() <em>Interface</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInterface()
	 * @generated
	 * @ordered
	 */
	protected Interface interface_;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected UsageImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return TfmcbsPackage.Literals.USAGE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Requier getRequier() {
		if (requier != null && requier.eIsProxy()) {
			InternalEObject oldRequier = (InternalEObject)requier;
			requier = (Requier)eResolveProxy(oldRequier);
			if (requier != oldRequier) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, TfmcbsPackage.USAGE__REQUIER, oldRequier, requier));
			}
		}
		return requier;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Requier basicGetRequier() {
		return requier;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetRequier(Requier newRequier, NotificationChain msgs) {
		Requier oldRequier = requier;
		requier = newRequier;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TfmcbsPackage.USAGE__REQUIER, oldRequier, newRequier);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRequier(Requier newRequier) {
		if (newRequier != requier) {
			NotificationChain msgs = null;
			if (requier != null)
				msgs = ((InternalEObject)requier).eInverseRemove(this, TfmcbsPackage.REQUIER__USAGES, Requier.class, msgs);
			if (newRequier != null)
				msgs = ((InternalEObject)newRequier).eInverseAdd(this, TfmcbsPackage.REQUIER__USAGES, Requier.class, msgs);
			msgs = basicSetRequier(newRequier, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TfmcbsPackage.USAGE__REQUIER, newRequier, newRequier));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Interface getInterface() {
		if (interface_ != null && interface_.eIsProxy()) {
			InternalEObject oldInterface = (InternalEObject)interface_;
			interface_ = (Interface)eResolveProxy(oldInterface);
			if (interface_ != oldInterface) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, TfmcbsPackage.USAGE__INTERFACE, oldInterface, interface_));
			}
		}
		return interface_;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Interface basicGetInterface() {
		return interface_;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetInterface(Interface newInterface, NotificationChain msgs) {
		Interface oldInterface = interface_;
		interface_ = newInterface;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TfmcbsPackage.USAGE__INTERFACE, oldInterface, newInterface);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setInterface(Interface newInterface) {
		if (newInterface != interface_) {
			NotificationChain msgs = null;
			if (interface_ != null)
				msgs = ((InternalEObject)interface_).eInverseRemove(this, TfmcbsPackage.INTERFACE__USAGES, Interface.class, msgs);
			if (newInterface != null)
				msgs = ((InternalEObject)newInterface).eInverseAdd(this, TfmcbsPackage.INTERFACE__USAGES, Interface.class, msgs);
			msgs = basicSetInterface(newInterface, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TfmcbsPackage.USAGE__INTERFACE, newInterface, newInterface));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case TfmcbsPackage.USAGE__REQUIER:
				if (requier != null)
					msgs = ((InternalEObject)requier).eInverseRemove(this, TfmcbsPackage.REQUIER__USAGES, Requier.class, msgs);
				return basicSetRequier((Requier)otherEnd, msgs);
			case TfmcbsPackage.USAGE__INTERFACE:
				if (interface_ != null)
					msgs = ((InternalEObject)interface_).eInverseRemove(this, TfmcbsPackage.INTERFACE__USAGES, Interface.class, msgs);
				return basicSetInterface((Interface)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case TfmcbsPackage.USAGE__REQUIER:
				return basicSetRequier(null, msgs);
			case TfmcbsPackage.USAGE__INTERFACE:
				return basicSetInterface(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case TfmcbsPackage.USAGE__REQUIER:
				if (resolve) return getRequier();
				return basicGetRequier();
			case TfmcbsPackage.USAGE__INTERFACE:
				if (resolve) return getInterface();
				return basicGetInterface();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case TfmcbsPackage.USAGE__REQUIER:
				setRequier((Requier)newValue);
				return;
			case TfmcbsPackage.USAGE__INTERFACE:
				setInterface((Interface)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case TfmcbsPackage.USAGE__REQUIER:
				setRequier((Requier)null);
				return;
			case TfmcbsPackage.USAGE__INTERFACE:
				setInterface((Interface)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case TfmcbsPackage.USAGE__REQUIER:
				return requier != null;
			case TfmcbsPackage.USAGE__INTERFACE:
				return interface_ != null;
		}
		return super.eIsSet(featureID);
	}

} //UsageImpl
